var co = require('./co')
// function* demoFn() {
//   console.log('开始执行第一段')
//   yield 'generator 1'
//   console.log('开始执行第二段')
//   yield 'generator 2'
//   console.log('开始执行第三段')
//   yield 'generator 3'
//   console.log('开始执行第四段')
//   yield 'generator 4'
//   console.log('执行结束')
//   return 'generator-end'
// }
// co(demoFn())
let request = (name, ms = 2000) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({ name })
    }, ms)
  })
}
function* getData() {
  console.log(999999)
  let name1 = yield request('cc')
  console.log('name1==', name1)
  let name2 = yield request(name1)
  console.log('name2==', name2)
  return name2
}
// co(getData())

async function foo() {
  console.log('foo')
}
async function bar() {
  console.log('bar start')
  await foo()
  console.log('bar end')
}
console.log('script start')
setTimeout(function () {
  console.log('setTimeout')
}, 0)
bar()
new Promise(function (resolve) {
  console.log('promise executor')
  resolve()
}).then(function () {
  console.log('promise then')
})
console.log('script end')
